<template>
    <div>
        <!--   实名注册审核   -->
        <el-form :inline="true" :model="form" class="demo-form-inline">
            <el-form-item>
                <el-input clearable v-model="form.applicant" style="width: 300px" placeholder="标题"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="query">搜索</el-button>
            </el-form-item>
        </el-form>
        <!--           列表-->
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="志愿者" name="first">
                <el-table display="none" :data="tableData" border>
            <!-- <template scope="scope"> -->
                <el-table-column
                    prop="name"
                    label="姓名"
                    align="center">
                </el-table-column>
                <el-table-column
                    prop="sex"
                    label="性别"
                    align="center">
                    <template slot-scope = "scope">
                        <span v-if="scope.row.sex == '0'">男</span>
                        <span v-if="scope.row.sex == '1'">女</span>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="tel"
                    label="联系电话"
                    align="center">
                </el-table-column>
                <el-table-column
                    prop="status"
                    label="状态"
                    align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.status == '0'">未审核</span>
                    <span v-if="scope.row.status == '1'">已通过</span>
                    <span v-if="scope.row.status == '2'">已退回</span>
                </template>
                </el-table-column>
            <!-- </template> -->
            <el-table-column
                    fixed="right"
                    label="操作"
                    align="center">
                <template slot-scope="scope">
                    <el-button
                            v-show="scope.row.status==='0'"
                            type="success"
                            size="mini"
                            @click="handleEdit(scope.row)">审核
                    </el-button>
                    <el-button
                            v-show="scope.row.status==='1'"
                            type="info"
                            size="mini" >已审核
                    </el-button>
                    <el-button
                            v-show="scope.row.status==='2'"
                            type="info"
                            disabled
                            size="mini">审核退回
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
            </el-tab-pane>
            <el-tab-pane label="志愿组织" name="second">
                <el-table display="none" :data="tableData" border>
            <!-- <template scope="scope"> -->
                <el-table-column
                    prop="organization_name"
                    label="组织名称"
                    align="center">
                </el-table-column>
                <el-table-column
                    prop="organization_Contacts"
                    label="组织联系人"
                    align="center">
                </el-table-column>
                <el-table-column
                    prop="organization_tel"
                    label="联系电话"
                    align="center">
                </el-table-column>
                <el-table-column
                    prop="status"
                    label="状态"
                    align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.status == '0'">未审核</span>
                    <span v-if="scope.row.status == '1'">已通过</span>
                    <span v-if="scope.row.status == '2'">已退回</span>
                </template>
                </el-table-column>
            <!-- </template> -->
            <el-table-column
                    fixed="right"
                    label="操作"
                    align="center">
                <template slot-scope="scope">
                    <el-button
                            v-show="scope.row.status==='0'"
                            type="success"
                            size="mini"
                            @click="handleEdit(scope.row)">审核
                    </el-button>
                    <el-button
                            v-show="scope.row.status==='1'"
                            type="info"
                            size="mini">审核通过
                    </el-button>
                    <el-button
                            v-show="scope.row.status==='2'"
                            type="info"
                            size="mini">审核退回
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
            </el-tab-pane>
        </el-tabs>
<!--        分页-->
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNo"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next"
                :total="totalRecord" class="text-center mt10">
        </el-pagination>

        <!-- 审核弹出框 -->
        <el-dialog title="审核" :visible.sync="dialogFormVisibleEdit"  width="650px">
            <el-radio-group v-model="radio" style="margin-left: 125px;margin-bottom: 20px;margin-top: 30px">
                <el-radio style="margin-left: 60px" :label="1" border>审核通过</el-radio>
                <el-radio style="margin-left: 60px" :label="0" border>不予通过</el-radio>
            </el-radio-group>

            <el-form v-show="this.radio =='0'">
                <el-form-item label="原因：">
                    <el-input
                            type="textarea"
                            v-model="reason"
                            autosize
                            placeholder="请填写原因"
                    >
                    </el-input>
                </el-form-item>
            </el-form>

            <div style="width: 160px; margin-left: 445px">
                <el-button @click="dialogFormVisibleEdit = false">取 消</el-button>
                <el-button type="primary" @click="auditsave">确 定</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<script>


    export default {

        name: 'test',

        data() {
            return {
                dialogFormVisibleEdit:false,//审核弹出框
                activeName: 'first',
                tableData: [],
                pageNo: 1,
                pageSize: 10,
                totalRecord: 0,
                totalPage: 0,
                form:{},
                formLabelWidth: '120px',
                auditid:'',
                radio:'',//单选、是否通过
                reason:''
            }
        },

        props: {},

        components: {},

        computed: {},

        methods: {
            // 初始化
            async init() {
                const res = await this.$http('selectAuditList',{
                    pageNo: this.pageNo,
                    pageSize: this.pageSize
                })
                console.log('res',res)
                this.tableData = res.results;
                this.totalPage = res.totalPage;
                this.totalRecord = res.totalRecord;
            },
            // //时间转换
            //  formatDate(value){
            //     // <!--例如后台传给我们的时间戳  -->
            //       this.value1= new Date(value.start_time);//value.createdTime是prop绑定的字段名称
            //       let dateValue = this.$moment(this.value1).format("YYYY-MM-DD");//$moment专门转化时间的插件（使用时需要下载引入）
            //       return dateValue
            // },
            async handleClick(tab, event) {
                console.log('event',event);
               if (tab.index == '0') {
                    const res = await this.$http('selectAuditList',{
                        pageNo: this.pageNo,
                        pageSize: this.pageSize
                    })
                    console.log('selectvolunteerlist',res)
                    this.tableData = res.results
                    this.totalPage = res.totalPage;
                    this.totalRecord = res.totalRecord;
                }else if(tab.index == '1'){
                    const res = await this.$http('selectTeamAuditList',{
                        pageNo: this.pageNo,
                        pageSize: this.pageSize
                    })
                    console.log('selectvolteamlist',res)
                    this.tableData = res.results
                    this.totalPage = res.totalPage;
                    this.totalRecord = res.totalRecord;
                }
            },
            //分页
            async handleSizeChange(val) {
                this.pageSize = val;
                this.init();
            },
            async handleCurrentChange(val) {
                this.pageNo = val;
                this.init();
            },
            
            
            //审核
            handleEdit(row){
                this.dialogFormVisibleEdit = true
                this.auditid = row.id
                this.ruleFormEdit = row
            },
            //审核确定
            async auditsave(){
                if(this.radio == '1'){
                    const res = await this.$http('createvolunteer',{
                        id :this.auditid,
                        status :'1'
                    })
                    if (res.count === 1) {
                    this.$message({
                        message: '审核成功',
                        type: 'success'
                    });
                    this.dialogFormVisibleEdit = false
                    this.init()
                    } else {
                        this.$message({
                            message: '审核失败',
                            type: 'error'
                        });
                    }
                }else if (this.radio == '0'){
                    const res = await this.$http('createvolunteer',{
                        id :this.auditid,
                        status :'2',
                        reason :this.reason
                    })
                    if (res.count === 1) {
                    this.$message({
                        message: '审核成功',
                        type: 'success'
                    });
                    this.dialogFormVisibleEdit = false
                    this.init()
                    } else {
                        this.$message({
                            message: '审核失败',
                            type: 'error'
                        });
                    }
                    }
                    console.log('res2323',res)
            },
            
            //搜索
            async query(){
                const res = await this.$http('selectAuditList',{
                    title:this.form.title
                })
                this.tableData = res.results
                this.totalPage = res.totalPage;
                this.totalRecord = res.totalRecord;
            }
        },

        watch: {},

        mounted() {
            this.init();
        },

    }
</script>

<style scoped>

</style>
